import MyRequest from './MyRequest';

const $ = new MyRequest({
	baseURL: 'http://192.168.1.5:3000/',
	timeout: 1000 * 30,
});

/** 请求拦截器 */
$.interface.reqeust = res => {
	console.log('request:', res);
	return res;
};

/** 响应拦截器 */
$.interface.response = res => {
	console.log('response:', res);

	return res.data;
};

/** 发送验证码 */
export const captchaSent = (data: object) =>
	$.request({
		url: 'captcha/sent',
		method: 'POST',
		data,
	});

/** 验证验证码 */
export const captchaVerify = (data: object) =>
	$.request({
		url: 'captcha/verify',
		method: 'POST',
		data,
	});

/** 手机号注册(修改密码)
 *  调用此接口 ,传入手机号码和验证码,密码,昵称, 可注册网易云音乐账号(同时可修改密码)
 */
export const registerCellphone = (data: object) =>
	$.request({
		url: 'register/cellphone',
		method: 'POST',
		data,
	});

/** 检测手机号码是否已注册 */
export const cellphoneCheck = (phone: number | string) =>
	$.request({
		url: 'cellphone/existence/check',
		method: 'POST',
		data: {
			phone,
		},
	});

/** 手机号登录 */
export const loginCellphone = (data: object) =>
	$.request({
		url: 'login/cellphone',
		method: 'POST',
		data,
	});

/** 推荐歌单 */
export const personalized = (limit: number = 8) =>
	$.request({
		url: 'personalized',
		method: 'POST',
		data: {
			limit,
		},
	});

/** 获取每日推荐歌曲 */
export const recommendSongs = (data: object) =>
	$.request({
		url: 'recommend/songs',
		method: 'POST',
		data,
	});

/** 推荐新音乐 */
export const personalizedNewsong = (limit: number = 10) =>
	$.request({
		url: 'personalized/newsong',
		method: 'POST',
		data: {
			limit,
		},
	});

/** 最新 mv */
export const mvFirst = (limit: number = 30) =>
	$.request({
		url: 'mv/first',
		method: 'POST',
		data: {
			limit,
		},
	});
